package indi.zn.commons.easiness;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class Coders {

	public static String md5(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException {

		MessageDigest md = MessageDigest.getInstance("MD5");
		byte[] bytes = md.digest(str.getBytes("utf-8"));
		return Bytes.toHex(bytes);
	}
	
	public static String BASE64Encode(String str){
		
		BASE64Encoder encoder = new BASE64Encoder();
		
		String encodedText = encoder.encode(str.getBytes());
		
		return encodedText;
		
	}
	
	public static String BASE64Dncode(String str) throws IOException{
		
		BASE64Decoder decoder = new BASE64Decoder();
		
	   String decoderText  =new String(decoder.decodeBuffer(str));
		
		return decoderText;
		
	}

}
